package com.machine.filling.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.machine.filling.R;

/**
 * Created by Administrator on 2018/2/24 0024.
 */

public class NoticeDialog extends Dialog implements View.OnClickListener {
    private Context mContext;
    private TextView tv_title;
    private TextView tv_content;
    private Button bt_left;
    private Button bt_right;

    public NoticeDialog(@NonNull Context context) {
        super(context, R.style.Translucent_NoTitle);
        mContext = context;
        initView();
    }

    private void initView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_notice,null);
        bt_left = (Button) view.findViewById(R.id.bt_left);
        bt_right = (Button) view.findViewById(R.id.bt_right);
        tv_title = (TextView) view.findViewById(R.id.tv_title);
        tv_content = (TextView) view.findViewById(R.id.tv_content);
        bt_left.setOnClickListener(this);
        bt_right.setOnClickListener(this);
        setCanceledOnTouchOutside(false);
        setContentView(view);
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    }

    public void setMyTitle(String title){
        tv_title.setText(title);
    }

    public void setMyContent(String content){
        tv_content.setText(content);
    }

    public NoticeDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.bt_left:
                if (iClickListener != null)
                iClickListener.clickLeft();
                break;
            case R.id.bt_right:
                if (iClickListener != null)
                iClickListener.clickRight();
                break;
        }
    }

    public interface IClickListener{
        void clickLeft();
        void clickRight();
    }

    public IClickListener iClickListener;

    public void setiClickListener(String leftStr,String rightStr,IClickListener iClickListener) {
        bt_left.setText(leftStr);
        bt_right.setText(rightStr);
        this.iClickListener = iClickListener;
    }
}
